'use strict';
const Service = require('egg').Service;
class ListService extends Service {
    // 新增文章
    async create(params) {
        try {
            await this.app.mysql.insert('list', {
                title: params.title,
                content: params.content,
                createDate: params.createDate
            });
            return {
                code: 200,
                message: "新增成功"
            };
        } catch (error) {
            return {
                message: error
            };
        }
    }
    // 删除文章
    async del(params) {
        try {
            await this.app.mysql.delete('list', {
                id: params.id
            });
            return {
                code: 200,
                message: "删除成功"
            };
        } catch (error) {
            return {
                message: error
            };
        }
    }
    // 修改文章
    async update(params) {
        console.log('params====>>>>>>>>', params);
        try {
            await this.app.mysql.update('list', {
                id: params.id,
                title: params.title,
                content: params.content,
                createDate: params.createDate
            });
            return {
                code: 200,
                message: "修改成功"
            };
        } catch (err) {
            return {
                message: error
            };
        }
    }


    //查询
    async find() {
        // "list" 为test数据库数据表名
        // const list = await this.app.mysql.query('select * from list', '');
        const list = await this.app.mysql.select('list')
        return {
            code: 200,
            data: list
        };
    }
}
module.exports = ListService;